<!DOCTYPE HTML>
<html>
<head>
    {include file="common:meta"}
    <link rel="stylesheet" type="text/css" href="/static/admin/plugin/treeTable/treeTable.css">
</head>
<body>
	<div class="wrap js-check-wrap">
		<ul class="nav nav-tabs">
			<li class="active"><a href="javascript:;">设置角色权限</a></li>
		</ul>
        <form class="js-ajax-form margin-top-20" id="form" data-url="/AuthorizeSave">
			<div class="table_full">
				<table class="table table-bordered" id="authrule-tree">
					<tbody>
						{$category|raw}
					</tbody>
				</table>
			</div>
			<div class="form-actions">
				<input type="hidden" name="roleId" value="{$roleId}" />
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                    <button class="btn btn-primary" type="button" onclick="commonSubmit(this)">提交</button>
                    <button class="btn btn-default" type="button" onclick="commonClose()">关闭</button>
                </div>
			</div>
		</form>
	</div>
    {include file="common:footer"}
    <script type="text/javascript" src="/static/admin/plugin/treeTable/treeTable.js"></script>

    <script type="text/javascript">
	$(document).ready(function () {
	        $("#authrule-tree").treeTable({
	            indent: 20
	        });
	});

    function checknode(obj) {
        var chk = $("input[type='checkbox']");
        var count = chk.length;

        var num = chk.index(obj);
        var level_top = level_bottom = chk.eq(num).attr('level');
        for (var i = num; i >= 0; i--) {
            var le = chk.eq(i).attr('level');
            if (le <level_top) {
                chk.eq(i).prop("checked", true);
                var level_top = level_top - 1;
            }
        }
        for (var j = num + 1; j < count; j++) {
            var le = chk.eq(j).attr('level');
            if (chk.eq(num).prop("checked")) {

                if (le > level_bottom){
                    chk.eq(j).prop("checked", true);
                }
                else if (le == level_bottom){
                    break;
                }
            } else {
                if (le >level_bottom){
                    chk.eq(j).prop("checked", false);
                }else if(le == level_bottom){
                    break;
                }
            }
        }
    }

    /**
     * 提交表单
     * @returns {boolean}
     */
//    function commonSubmit(obj) {
//        var form = $("#form");
//        $(obj).attr('disabled', true).addClass('disabled');
//        var url_ = form.attr('data-url');
//        $.ajax({
//            url: url_,
//            type: 'POST',
//            dataType: 'json',
//            data: form.serialize(),
//            success: function (re) {
//                console.log(re);
//                $(obj).removeAttr('disabled', true).removeClass('disabled');
//                if (re.code === 1) {
//                    layer.msg(re.msg, {
//                        icon: 1,
//                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
//                    }, function () {
//                        re.url ? window.location.href = re.url : '';
//                    });
//                } else {
//                    layer.alert(re.msg);
//                }
//            }
//        });
//        return false;
//    }

    /**
     * 关闭layer弹出层
     */
    function commonClose() {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }








	</script>
</body>
</html>